#ifndef __MY_EMS_POWER_H__
#define __MY_EMS_POWER_H__

#include "n32l40x.h"
#include "my_gpio.h"

#define EMS_OUTPUT_CTRL_PORT    GPIOD
#define EMS_OUTPUT_CTRL_PIN     GPIO_PIN_14

#define EMS_OUTPUT_ENABLE()     set_pin_high(EMS_OUTPUT_CTRL_PORT, EMS_OUTPUT_CTRL_PIN)
#define EMS_OUTPUT_DISABLE()    set_pin_low(EMS_OUTPUT_CTRL_PORT, EMS_OUTPUT_CTRL_PIN)

// V1.1 版本取消ems使能脚，将改脚位重新定义为ems检测脚
#define EMS_POWER_EN_PORT     GPIOA
#define EMS_POWER_EN_PIN      GPIO_PIN_7
#define EMS_POWER_ON()        set_pin_high(EMS_POWER_EN_PORT, EMS_POWER_EN_PIN)
#define EMS_POWER_OFF()       set_pin_low(EMS_POWER_EN_PORT, EMS_POWER_EN_PIN)

/************************
 *  ems输出检测脚
 *  硬件电路说明---无负载时，ems检测脚位为高电平
 *             ---有负载时，ems脚位为低电平。
 */ 
#define EMS_LOAD_DET_PORT           (GPIOB)
#define EMS_LOAD_DET_PIN            (GPIO_PIN_14)

#define IS_EMS_LOAD_ACTIVE()        (Bit_RESET == GPIO_ReadInputDataBit(EMS_LOAD_DET_PORT, EMS_LOAD_DET_PIN))

void ems_output_enable(void);
void ems_output_disable(void);
void ems_power_on(void);
void ems_power_off(void);
void ems_power_en_off(void);

void my_ems_power_init(void);

#endif

